import xlrd
import xlwt
from xlwt import Workbook
from xlrd import xldate_as_tuple
import datetime

file = '改动.xlsx'
def read_excel():
    wb = xlrd.open_workbook(filename = file)
    today = str(datetime.datetime.now())[0:10]
    
    for name in ['进货明细','门店调拨各明细','报销，已付货款明细','个人批发']:
        pinzhong = []
        shuliang = []
        danjia = []
        sheet = wb.sheet_by_name(name)
        print(today)
        for i in range(200):
            try:
                if sheet.cell(2+i,0).ctype == 3:
                    date = xldate_as_tuple(sheet.cell(2+i,0).value,0)
                    if date[2] < 10:
                        d = str(date[0])+'-0'+str(date[1])+'-0'+str(date[2])
                    else:
                        d = str(date[0])+'-0'+str(date[1])+'-'+str(date[2])
                    print(d)
                if d == today:
                    print(1)
                    pinzhong += sheet.col_values(2)[2+i]
            except IndexError:
                break
        print(pinzhong)
    pz = []
    for i in pinzhong:
        if i not in pz and i != '' and '费' not in i:
            pz.append(i)
    print(pz,len(pz))
'''
    #将数据写入新Excel
    book = Workbook(encoding='utf-8')
    sheetname = '库存统计'
    sheet1 = book.add_sheet(sheetname)
    for i in range(len(pz)):
        sheet1.write(i+1,0,pz[i])
    title = '临时统计.xlsx'
    book.save(title)
    '''
read_excel()
